<?php
namespace app\admin\validate;

use think\Validate;
use think\Db;

class User extends Validate{
    protected $rule = [
        'username'  => 'require|unique:User|min:2|max:14',
        'tel' => 'require|unique:User|regex:/^1[345678]\d{9}/',
        //'email'   => 'require|unique:User|email',
        'password'   => 'require|unique:User|min:5|max:16',
    ];
    protected $message = [
        'username.require'  => '用户名不能为空',
        'username.unique'  => '用户名已存在',
        'username.min'  => '用户名最小长度为2个字符',
        'username.max'  => '用户名最大长度为14个字符',
        'tel.require' => '手机号不能为空',
        'tel.regex' => '手机号格式不正确',
        'tel.unique' => '手机号已存在',
        //'email.require' => '邮箱不能为空！',
        //'email.email' => '邮箱格式不正确！',
        'email.unique' => '邮箱已存在！',
        'password.require'  => '密码不能为空',
        'password.min'    => '密码长度不能小于5位数',
        'password.max'    => '密码长度不能大于16位数',
    ];
    protected $scene=[
        'add_member'=>['username','tel','password'],
        'edit_member'=>['username','tel'],
    ];
}